package cn.xscrum.vtsp.controller;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspActivityAppraise;
import cn.xscrum.vtsp.service.IVtspActivityAppraiseService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 活动评价信息Controller
 * 
 * @author Zxing
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/activity_appraise")
public class VtspActivityAppraiseController extends BaseController {
    //静态资源前缀
    private String prefix = "vtsp/activity_appraise";

    @Autowired
    private IVtspActivityAppraiseService vtspActivityAppraiseService;

    /**
     * 返回静态资源templates中的"/vtsp/activity_appraise/activity_appraise"视图
     */
    @RequiresPermissions("vtsp:activity_appraise:view")
    @GetMapping()
    public String activity_appraise() {
        return prefix + "/activity_appraise";
    }

    /**
	 * 查询活动评价信息列表
     */
    @RequiresPermissions("vtsp:activity_appraise:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspActivityAppraise vtspActivityAppraise) {
        startPage();
        //  因为传来的结束时间是yyyy-MM-dd 00:00:00, 将结束时间往后挪至次日前一秒
        if(vtspActivityAppraise.getEndDate() != null) {
            //  Date -> 时间戳
            long timeStamp = vtspActivityAppraise.getEndDate().getTime();
            //  时间戳 + (一天的秒数 - 1) * 1000
            timeStamp += (24 * 60 * 60 - 1) * 1000;
            //  时间戳 -> Date
            vtspActivityAppraise.setEndDate(new Date(timeStamp));
        }
        //  根据vtspActivityAppraise对象的属性进行条件查询
        List<VtspActivityAppraise> list = vtspActivityAppraiseService.selectVtspActivityAppraiseList(vtspActivityAppraise);
        return getDataTable(list);
    }

    /**
	 * 删除活动评价信息
     */
    @RequiresPermissions("vtsp:activity_appraise:remove")
    @Log(title = "活动评价信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(vtspActivityAppraiseService.deleteVtspActivityAppraiseByIds(ids));
    }










    //未用到的方法------------------------------------------------------------------------------------------------------
    /**
     * 导出活动评价信息列表
     */
    @RequiresPermissions("vtsp:activity_appraise:export")
    @Log(title = "活动评价信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspActivityAppraise vtspActivityAppraise)
    {
        List<VtspActivityAppraise> list = vtspActivityAppraiseService.selectVtspActivityAppraiseList(vtspActivityAppraise);
        ExcelUtil<VtspActivityAppraise> util = new ExcelUtil<VtspActivityAppraise>(VtspActivityAppraise.class);
        return util.exportExcel(list, "activity_appraise");
    }

    /**
     * 新增活动评价信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存活动评价信息
     */
    @RequiresPermissions("vtsp:activity_appraise:add")
    @Log(title = "活动评价信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspActivityAppraise vtspActivityAppraise)
    {
        return toAjax(vtspActivityAppraiseService.insertVtspActivityAppraise(vtspActivityAppraise));
    }

    /**
     * 修改活动评价信息
     */
    @GetMapping("/edit/{appraiseId}")
    public String edit(@PathVariable("appraiseId") Long appraiseId, ModelMap mmap)
    {
        VtspActivityAppraise vtspActivityAppraise = vtspActivityAppraiseService.selectVtspActivityAppraiseById(appraiseId);
        mmap.put("vtspActivityAppraise", vtspActivityAppraise);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动评价信息
     */
    @RequiresPermissions("vtsp:activity_appraise:edit")
    @Log(title = "活动评价信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspActivityAppraise vtspActivityAppraise)
    {
        return toAjax(vtspActivityAppraiseService.updateVtspActivityAppraise(vtspActivityAppraise));
    }
}
